Search
Other Articles Field questions
Forum

{foreach} in Articles Field Layout?

Crystal Dionysopoulos's Avatar Crystal Dionysopoulos
Hi Peter!

I hope you're doing well 🙂

I am using articles field and articles anywhere on a client site. One thing I'm trying to do is use the data from a subform custom field in the article field layout. I followed the documentation but it seems that
foreach
doesn't work in the articles field layout?

One complicating factor (maybe) is that the subform is not repeatable, so not sure that foreach even makes sense in this case.

Have you run across this use case before? What would you advise?

Thank you!!
Crystal
Andrea Malalana's Avatar Andrea Malalana ADMIN
You can combine Articles Field with Articles Anywhere, see:
docs4.regularlabs.com/articlesfield/goin...rther/more-data-tags

This allows you to use all the Data Tags from Articles Anywhere inside Articles Field, so even a subform field.
Crystal Dionysopoulos's Avatar Crystal Dionysopoulos
Hi Andrea,

Thanks for your reply. Please reread my original message. I am using articles anywhere and already referenced the documentation. Other things are working but {foreach} tags are not.
Peter van Westen's Avatar Peter van Westen ADMIN
Hi Crystal,

Hope you are doing well too!

What code have you placed in the Custom HTML layout field?
Please post a rating at the Joomla! Extensions Directory
Crystal Dionysopoulos's Avatar Crystal Dionysopoulos
This is the code in the articles field layout:
<aside>
{article [id]}
    {foreach data="page-preview"}
        <article class="card outline" data-accent-color="[row:icon-color:value]">
            <div class="inner-content">
            {if [row:icon:value]}
                <span class="icon-mask large" data-icon-color="[row:icon-color:value]" aria-hidden="true" style="--icon-source:url([row:icon:value])"></span>
            {/if}
                <div class="titles">
                    <h3 class="h4">
                        {if row:title:value}
                            [row:title:value]
                        {else}
                            [title]
                        {/if}
                    </h3>
                </div>
                {row:summary:value}
                <p class="cta">
                    <a href="[url]" class="btn-solid-flex arrow">Learn More</a>
                </p>
            </div>
        </article>
    {/foreach}
{/article}
</aside>

And this is how it renders:
Confidential information:
(hidden)
Peter van Westen's Avatar Peter van Westen ADMIN
Are you able to place that code in a test article, to see it it works there?
Of course, replaced [id] with an article id…

Then we can see if the issue is isolated to Articles Anywhere or not.

PS: best to use
{article id="…"}
instead of
{article …}
Please post a rating at the Joomla! Extensions Directory
Crystal Dionysopoulos's Avatar Crystal Dionysopoulos
Thank you Peter!

I have also put it in an editor field; it is not working either. Could it be because the editor field and articles field are both in subforms themselves?
Peter van Westen's Avatar Peter van Westen ADMIN
Maybe… and what if you put it in the normal article text? So just to test the Articles Anywhere code by itself.
Please post a rating at the Joomla! Extensions Directory
Crystal Dionysopoulos's Avatar Crystal Dionysopoulos
Nope, same result.

Echoing just the field without doing the foreach works:
[page-preview]

So I'm wondering if it's because it's not a repeatable subform?

I'm using the subform to collect related fields into one so it's easier for my clients to manage, and in this case there's only ever one row. I've noticed some inconsistencies with how Joomla handles subforms that aren't repeatable; sometimes there's an array with one entry, and sometimes it's just the json of the subform fields without the parent array.

So, when I'm calling the fields directly from a template override, I have to check whether it's an array or not first.
Peter van Westen's Avatar Peter van Westen ADMIN
I haven't been able to reproduce the issue.

I have tested the {foreach} on repeatable and non-repeatable subform fields without issues.
So I guess it is easiest if I can see it in action on your setup, and see what the data is formed like in the database.

Can you give me (super) admin, (s)ftp and database (PhpMyAdmin) access so I can take a look?
You can use the 'Confidential information' button in the forum editor to hide sensitive information.
Please post a rating at the Joomla! Extensions Directory
Crystal Dionysopoulos's Avatar Crystal Dionysopoulos
No problem:

Confidential information:
(hidden)
Peter van Westen's Avatar Peter van Westen ADMIN
I think I found the cause of this.
It should now be fixed in the latest development release on:
regularlabs.com/development-releases
Can you test?
Please post a rating at the Joomla! Extensions Directory
Crystal Dionysopoulos's Avatar Crystal Dionysopoulos
Would you be able to install it? My client has an active subscription to Articles Anywhere (you can verify with the download ID in the site), but I do not so can't access it. :/
Peter van Westen's Avatar Peter van Westen ADMIN
It is now installed...
Please post a rating at the Joomla! Extensions Directory
Crystal Dionysopoulos's Avatar Crystal Dionysopoulos
Thank you! It looks like it's now no longer displaying anything at all though 🙁
Peter van Westen's Avatar Peter van Westen ADMIN
I think the issue is with the {if} tags.
Currently {if} tags do not work inside the {foreach} tags.
They are executed before the {foreach} tags and only work on the data attached to the main article of that loop.
Please post a rating at the Joomla! Extensions Directory
Peter van Westen's Avatar Peter van Westen ADMIN
I'll see if I can get this working, but will probably not be before Monday.
Please post a rating at the Joomla! Extensions Directory
Peter van Westen's Avatar Peter van Westen ADMIN
I think I have it working now in the latest dev version.
I installed it on that website. Can you check if everything is working?

You have a {row:summary:value} in your output now, but that is because you should be using the square brackets for Data Tags: [row:summary:value]
Please post a rating at the Joomla! Extensions Directory
Crystal Dionysopoulos's Avatar Crystal Dionysopoulos
This is great. Thank you so much for your help!! I really appreciate it.

Also I was surprised to receive a reply over the weekend at all, so absolutely no worries 🙂 Hope you had a great weekend.
Peter van Westen's Avatar Peter van Westen ADMIN
surprised to receive a reply over the weekend
Aren't you married to a guy that also never sleeps? 😁
Please post a rating at the Joomla! Extensions Directory
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription